﻿//反填

$(function () {
    fantian2();//已采购信息
    fantSup();//供应商信息
    fantLog();//物流信息

})
//查看已采购消息
function fantian2() {
    // 发送AJAX请求获取数据
    console.log(localStorage.getItem("purchaseID"))
    $.ajax({
        type: "get",
        url: "/Purch/FabPurch",
        data: {
            PurchaseID: localStorage.getItem("purchaseID"),
            token: localStorage.getItem("token")
        },
        success: function (res) {
            var ter = JSON.parse(res)
            console.log(ter.data)

            $(ter.data).each(function () {
                localStorage.setItem("purchaseID", this.purchaseID)
                $('#purchaseCode2').val(this.purchaseCode);
                $('#ingredientName2').val(this.ingredientName);
                $('#ingredientnumber2').val(this.ingredientnumber);
                $('#purchaseNumber2').val(this.purchaseNumber);
                $('#purchaseDate2').val(this.purchaseDate);
                //$('#purchaseDate2').val(this.purchaseDate.substring(0,10));
                $('#createdDate2').val(this.createdDate);
                $('#purchaseBatch2').val(this.purchaseBatch);
                $('#purchaseSart2').val(this.purchaseSart);
                $('#createdBy2').val(this.createdBy);
                $('#purchaseBudget2').val(this.purchaseBudget);
                $('#purchaseSumMoney2').val(this.purchaseSumMoney);
                $('#purchasePrice2').val(this.purchasePrice);
                $('#purchasePayPrice2').val(this.purchasePayPrice);
                $('#payType').val(this.payType);

            })

        },

    });


}
//查看供应商消息
function fantSup() {
    // 发送AJAX请求获取数据
    console.log(localStorage.getItem("purchaseID"))
    $.ajax({
        type: "get",
        url: "/Purch/SupListPurch",
        data: {
            PurchaseID: localStorage.getItem("purchaseID"),
            token: localStorage.getItem("token")
        },
        success: function (res) {
            var ter = JSON.parse(res)
            console.log(ter.data)

            $(ter.data).each(function () {
                localStorage.setItem("supplierID", this.supplierID)
                $('#supplierCode').val(this.supplierCode);
                $('#supplierName').val(this.supplierName);
                $('#curator').val(this.curator);
                $('#curatorPhone').val(this.curatorPhone);
              

            })

        },

    });


}
//查看物流消息
function fantLog() {
    // 发送AJAX请求获取数据
    console.log(localStorage.getItem("purchaseID"))
    console.log(localStorage.getItem("supplierID"))
    $.ajax({
        type: "get",
        url: "/Purch/LogList",
        data: {
            SupplierID: localStorage.getItem("supplierID"),
            PurchaseID: localStorage.getItem("purchaseID"),
            token: localStorage.getItem("token")
        },
        success: function (res) {
            var ter = JSON.parse(res)
            console.log(ter.data)

            $(ter.data).each(function () {
                localStorage.setItem("logisticsId", this.logisticsId)
                $('#logisticsCode').val(this.logisticsCode);
                $('#createdDatelog').val(this.createdDate.replace("T"," "));
                $('#payTime').val(this.payTime.replace("T", " "));
             
            })

        },

    });


}
//提醒发货
window.ShowUpd = function ShowUpd() { 
  
    $.ajax({
        url: '../Purch/UpdateLog',
        type: 'post',
        data: {
            LogisticsId: localStorage.getItem("logisticsId"),
            token: localStorage.getItem("token"),
        },
        success: function (res) {
            var res = JSON.parse(res)
            console.log(res);
            if (res.code > 0) {
                layer.alert("提醒发货成功");
               location.href = '/Purch/ListLogShow'
            } else {
                layer.alert("提醒发货失败");
            }
        }
    });

    return false; // 阻止默认 form 跳转
};





